package homework.day15;

public class test01 {
    public static void main(String[] args) {
        Object obj = new Object();
        // 启动两个线程
        T1 t1 = new T1(obj);

        T2 t2 = new T2(obj);

        t1.start();
        t2.start();
    }

}
class T1 extends Thread{
    private Object obj;
    public T1 (Object obj){
        this.obj=obj;
    }

    @Override
    public void run() {
        synchronized (obj){
            for (int i = 1; i <53 ; i++) {
                System.out.println(i+" ");
                if(i%2==0){
                    obj.notifyAll();
                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
class T2 extends Thread{
    private Object obj;
    public T2 (Object obj){
        this.obj=obj;
    }

    @Override
    public void run() {
        synchronized (obj){
            for (int i = 0; i <26 ; i++) {
                System.out.println((char)('A'+i)+"");
                obj.notifyAll();
                if(i!=25){
                    try {
                        obj.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
